package java_class_work.week06;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Auther: admin
 * @Date: 2022/10/17 16:25
 * @Description: Collections集合工具类
 */
public class CollectionDemo01 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        // 添加元素
        Collections.addAll(list,"item1","item2","item3");
        System.out.println(list);
        // 翻转
        Collections.reverse(list);
        System.out.println(list);
        // 随机打乱
        Collections.shuffle(list);
        System.out.println(list);
        // 排序
        Collections.sort(list);
        System.out.println(list);
        // 交换元素位置
        Collections.swap(list,0,2);
        System.out.println(list);
        // 返回集合中最大值
        System.out.println(Collections.max(list));
        // 后移（旋转）指定距离
        Collections.rotate(list,2);
        System.out.println(list);
    }
}
